<?php
	session_start();
	if(!$_SESSION["username"]){
		//not logged in
		header("location:login.php");
	}
	
	// Connect to server and select databse.
	mysql_connect("localhost", "root", "")or die("cannot connect"); 
	mysql_select_db("Project 5.5")or die("cannot select DB");
	
	global $groupid;		
	global $userid;
	$sql="SELECT User_ID FROM users WHERE Username='".$_SESSION['username']."'";
	$result=mysql_fetch_row(mysql_query($sql));
	$userid = $result[0];

	$sql="SELECT Group_ID FROM studentinfo WHERE User_ID='".$userid."'";

	$result=mysql_fetch_row(mysql_query($sql));
	$groupid=$result[0];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>Home</title>
		<script type="text/javascript" src="js/formsValidate.js"/></script>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link href="css/main.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="topbar">
			<div id="qut_logo" />  
			<img src="../img/strapline.png" alt="Slogan" id="slogan"/>
		</div>
		<div id="menubar">
			<div id="breadcrumbs">
				<a href="index.php">Home</a>
			</div>
			<div id="logout"> 
				<a href="login.php?destroy=true">Log Out</a>
			</div>
		</div>
		<div id="namebar_home"></div>
		<div id="body">
		<br/>
			<div style=" background-color:#FFF; margin-bottom:30px; margin-left:10%; margin-right:10%;" >
				<div style="background-color: #CCC;font-size:25pt;font-weight:bold;">Welcome <?php echo ' '.$_SESSION['firstname'].' '.$_SESSION['lastname'];?></div>
            <table style="text-align:center;" align="center" width="600px" border="0">
				<tr>
					<?php
						//shows different content based on user role.
						switch($_SESSION["role"]){
							case "TUT":
								echo '<td width="250px"><h2><a href="management.php"> <img src="img/Managerbtn.png" width="159" height="160" alt="Management" /> Management </a></h2></td>';
								echo '<td width="250px"><h2><a href="email.php"><img src="img/emailbtn.png" width="159" height="160" alt="Email" />  Email  </a></h2></td>';
								echo '<td width="250px"><h2><a href="statistics.php">  <img src="img/Stats_ico.png" width="159" height="160" alt="Statistics" /><br/>Statistics </a></h2></td>';
								break;
							case "STU":
								echo '<td width="250px"><h2><a href="groups.php">  <img src="img/Groupsbtn.png" width="159" height="160" alt="Groups" /><br/>Groups </a></h2></td>';
								echo '<td width="250px"><h2><a href="results.php?userid=';
								echo $userid;
								echo '">  <img src="img/Results_ico.png" width="159" height="160" alt="Results" /><br/>Results </a></h2></td>';

								if(!($groupid==0)){
									$sql="SELECT Group_Members FROM groups WHERE Group_ID=".$groupid;
									$result=mysql_fetch_row(mysql_query($sql));
									$members=explode(',',$result[0]);
									
									if (sizeof($members)>1) {
										echo '<td width="250px"><h2><a href="peer-review.php?groupid=';
										echo $groupid;
										echo '"> <img src="img/Reviewbtn.png" width="159" height="160" alt="Online Peer Review" /><br/> Online Peer Review  </a></h2></td>';
									}
								}
								break;
						}
					?>
				</tr>
			</table>
			</div>
			<br/>
		</div>
		<div id="bottombg">
			<p>
				<a style="color:#333" href="http://www.qut.edu.au/additional/privacy">Privacy</a> 
				|
				<a style="color:#333" href="http://www.qut.edu.au/additional/copyright">Copyright</a>
				|
				<a style="color:#333" href="http://www.qut.edu.au/additional/disclaimer">Disclaimer</a>
				|
				<a style="color:#333" href="http://www.qut.edu.au/additional/accessibility">Accessibility</a>
			</p>
		</div>
	</body>
</html>